package mumu.android.lib.view.webview;

import mumu.android.R;
import android.app.Activity;
import android.graphics.drawable.AnimationDrawable;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewTreeObserver.OnPreDrawListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

public class WebViewLoading {
	class G {
		RelativeLayout rly_container;
		LinearLayout rly_loading;
		LinearLayout ly_error;
		ILoading iLoading;
		TextView txt_error;
		TextView txt_loadingstr;
	}

	// 接口
	public interface ILoading {
		public void reload();
	}

	public WebViewLoading(View v) {
		initG(v);
	}

	// 传View进来
	private void initG(View v) {
		g.txt_loadingstr = (TextView) v.findViewById(R.id.txt_loadingstr);
		g.txt_error = (TextView) v.findViewById(R.id.txt_error);
		g.rly_loading = (LinearLayout) v.findViewById(R.id.rly_loading);
		g.rly_container = (RelativeLayout) v;
		g.ly_error = (LinearLayout) v.findViewById(R.id.ly_error);
		g.rly_loading.setVisibility(View.GONE);
		g.ly_error.setVisibility(View.GONE);
	}

	public void setLoadStr(String text) {
		g.txt_loadingstr.setText(text);
	}

	public void setErrorTxt(String text) {
		g.txt_error.setText(text);
	}

	G g = new G();

	public void Loading() {
		g.rly_container.setVisibility(View.VISIBLE);
		g.rly_loading.setVisibility(View.VISIBLE);
		g.ly_error.setVisibility(View.GONE);
	}

	public void error(final ILoading iLoading) {
		g.rly_container.setVisibility(View.VISIBLE);
		g.rly_loading.setVisibility(View.GONE);
		g.ly_error.setVisibility(View.VISIBLE);
		g.ly_error.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (iLoading != null)
					iLoading.reload();

			}
		});
	}

	public void hide() {
		g.rly_container.setVisibility(View.GONE);
	}
}
